package com.brokendust.client.listener;

import com.brokendust.client.PixelEngine;
import com.brokendust.client.manager.ClientManager;
import com.brokendust.client.task.LoginTask;
import net.minecraft.client.gui.screen.Screen;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class PlayerListener {
    public static void onReceiveServerMessage(String message) {
        String[] strings = message.split(" : ");
        if (strings.length == 2) {
            LoginTask.execute(strings[0], strings[1]);
        }
    }

    @SubscribeEvent
    public void onGuiOpen(GuiOpenEvent event) {
        Screen screen = event.getGui();
        if (screen == null) {
            if (ClientManager.gui_open) {
                PixelEngine.pixelConnect.send("closegui", ClientManager.menu.menu_name);
                ClientManager.gui_open = false;
            }
        }
        else {
            String guiName = screen.getTitle().getString();
            if (guiName.equals("PixelGui")) {
                PixelEngine.pixelConnect.send("opengui", ClientManager.menu.menu_name);
                ClientManager.gui_open = true;
            }
        }
    }
}
